import { reqGetPeople,reqGetPeople2,reqGet,login,regist,reqGetActiveId,reqgetShopList,reqGetCounts,reqGetShop } from "@/api";

const state = {
    people:[],
    people2:[],
    name:'',
    loginInf:'',
    registInf:'',
    ActiveId:{},
    shopList:[],
    counts:'',
    shop:''
};

const mutations = {
    REQGETPEOPLE(state,people) {
        state.people = people;
    },
    GETPEOPLE2(state,people2) {
        state.people2 = people2;
    },
    REQGET(state,name) {
        state.name = name;
    },
    GETLOGIN(state,loginInf) {
        state.loginInf = loginInf;
    },
    GETREGIST(state,registInf) {
        state.registInf = registInf;
    },
    GETID(state,ActiveId) {
        state.ActiveId = ActiveId;
    },
    GETSHOPLIST(state,shopList) {
        state.shopList = shopList;
    },
    GETCOUNTS(state,counts) {
        state.counts = counts;
    },
    GETSHOP(state,shop) {
        state.shop = shop;
    }
};

const actions = {
    async getPeople({commit},Inf) {
        const result = await reqGetPeople(Inf);
        if(result.code == 0) {
            commit("REQGETPEOPLE",result.data);
        }
    },
    async getPeople2({commit},Inf) {
        const Inf2 = {
            token:Inf.token
        }
        const result = await reqGetPeople2(Inf.count,Inf2);
        if(result.code == 0) {
            commit("GETPEOPLE2",result.data);
        }
    },
    async reqGet({commit},name) {
        const result = await reqGet(name);
        if(result.code == 1) {
            commit("REQGET",result.data);
        }
    },
    async getLogin({commit},Inf) {
        const result = await login(Inf.name,Inf.psd);
        if(result.code == 0) {
            commit("GETLOGIN",result.data);
        }
    },
    async getRegist({commit},registInf) {
        const result = await regist(registInf);
        if(result.code == 0) {
            commit("GETREGIST",result.data);
        }
    },
    async getId({commit},Inf) {
        const result = await reqGetActiveId(Inf);
        if(result.code == 0) {
            commit("GETID",result.data);
        }
    },
    async getShopList({commit},Inf) {
        const Inf2 = {
            token:Inf[1].token
        }
        const result = await reqgetShopList(Inf[0].name,Inf2);
        if(result.code == 0) {
            commit("GETSHOPLIST",result.data);
        }
    },
    async getCounts({commit},Inf) {
        const Inf2 = {
            token:Inf.token
        }
        const result = await reqGetCounts(Inf2,Inf.activityId);
        if(result.code == 0) {
            commit("GETCOUNTS",result.data);
        } else if (result.code == 402) {
            commit("GETCOUNTS",result.msg);
        }
    },
    async getShop({commit},Inf) {
        const Inf2 = {
            token:Inf.token
        }
        const result = await reqGetShop(Inf2,Inf.activeName);
        if(result.code == 0) {
            commit("GETSHOP",result.data);
        }
    }
};

const getters= {}

export default {
    state,
    actions,
    mutations,
    getters
}